<?php

$mForm = new FormTemplate();
$mQuery = new DBQueryParse();
$mValidation = new InputValidation();

//ACTION CODE
$mValidation->SetInput($_POST['fAct']);
$mValidation->SetPattern(pAct);
$tAct = $mValidation->CheckValidation();
////
//BACK ID
$mValidation->SetInput($_POST['fBackId']);
$mValidation->SetPattern(pPegawaiId);
$mBackId = $mValidation->CheckValidation();
////
//SETTING UP : EDIT FORM
$tNIPEditAuth= true;
if ($tAct == "edt") {
    if ($_SESSION['User']['Level'] == "9996" || $_SESSION['User']['Level'] == "168") {
        $tNIPEditAuth = true;
    } else {
        $tNIPEditAuth = false;
    }

    //ID FAKULTAS
    $mValidation->SetInput($_POST['fId']);
    $mValidation->SetPattern(pPersonId);
    $tPersonId = $mValidation->CheckValidation(); //PERSON ID

    $mForm->SetAction("edt");
    $tSQL = 'SELECT id_person, nip, nama_lengkap, alamat, telepon, kota_lahir_id, tanggal_lahir, kelamin_id, goldarah_id, agama_id, kota_id, jabatan_id FROM view_hrs_pegawai WHERE id_person="' . $tPersonId . '" ';
    $tResEdit = $mQuery->Execute($tSQL); //echo $tSQL;

    if ($tResEdit->MoveNext()) {
        //SETUP ID PK AWAL, digunakan untuk keperluan ID awal jika ada perubahan ID PK
        $mForm->SetCurrentId($tResEdit->nip);


        //UBAH FORMAT TANGGAL LAHIR
        $tTemp = explode("-", $tResEdit->tanggal_lahir);
        $tTanggalLahir = $tTemp[2] . "/" . $tTemp[1] . "/" . $tTemp[0];

        //MENITIP NILAI EDIT KE VARIABEL GLOBAL, "$_POST[EDIT_"NAMAVAR"]"
        $_POST['fId'] = $tResEdit->nip;
        $_POST['EDIT_fId'] = $tResEdit->nip;
        $_POST['EDIT_fNama'] = $tResEdit->nama_lengkap;
        ;
        $_POST['EDIT_fJabatan'] = $tResEdit->jabatan_id;
        $_POST['EDIT_fKotaLahir'] = $tResEdit->kota_lahir_id;
        $_POST['EDIT_fTanggalLahir'] = $tTanggalLahir;
        $_POST['EDIT_fKelamin'] = $tResEdit->kelamin_id;
        $_POST['EDIT_fAgama'] = $tResEdit->agama_id;
        $_POST['EDIT_fGoldarah'] = $tResEdit->goldarah_id;
        $_POST['EDIT_fKota'] = $tResEdit->kota_id;
        $_POST['EDIT_fAlamat'] = $tResEdit->alamat;
        $_POST['EDIT_fTelepon'] = $tResEdit->telepon;
    }
} else {
    $mForm->SetMultiForm(true);
    $mForm->SetAction("add");
}


//SETUP: FORM
$mForm->SetFormName("formPegawai");
$mForm->SetFormMethod("post");
$mForm->SetFormTargetAction("main.php?menu=12&submenu=319");
$mForm->SetFormTargetBack("main.php?menu=12&submenu=311");
$mForm->SetFormBackId($mBackId);
$mForm->SetFormTitle("FORM PEGAWAI");
/* $mForm->CreateInputForm("text");
  $mForm->SetTitle("FORM MAHASISWA"); */


//SETUP INFO
/* EMPTY */
////
//SETUP: OPTION VALUE
$tSQL = 'SELECT id_kota as id, CONCAT(nama_propinsi, " - ", nama_kota) as value FROM app_master_kota kot JOIN app_master_propinsi pro ON (kot.propinsi_id=pro.id_propinsi) ORDER BY pro.nama_propinsi, kot.nama_kota';
$tResKotaLahirOption = $mQuery->Execute($tSQL);
$tResKotaOption = $mQuery->Execute($tSQL);

$tSQL = 'SELECT id_agama as id, nama_agama as value FROM app_master_agama';
$tResAgamaOption = $mQuery->Execute($tSQL);

$tSQL = 'SELECT id_goldarah as id, nama_goldarah as value FROM app_master_goldarah';
$tResGoldarahOption = $mQuery->Execute($tSQL);

$tSQL = 'SELECT id_kelamin as id, nama_kelamin as value FROM app_master_kelamin';
$tResKelaminOption = $mQuery->Execute($tSQL);

$tSQL = 'SELECT id_jabatan as id, nama_jabatan as value FROM hrs_jabatan WHERE id_jabatan != "RES002" ORDER BY nama_jabatan';
$tResJabatanOption = $mQuery->Execute($tSQL);
////


$mForm->CreateInputForm();

//JIKA EDIT MAKA TAMBAHKAN PERSON ID
if ($tAct == "edt") {
    $mForm->CreateInputForm();
    $mForm->SetType('hidden');
    $mForm->SetName('fPersonId');
    $mForm->SetValue($tPersonId);
}

$mForm->CreateInputForm();
if ($tNIPEditAuth === true)
    $mForm->SetType('text');
else
    $mForm->SetType('hidden');

$mForm->SetName('fId');
$mForm->SetCaption('Kode Pegawai (NIP)');
$mForm->SetIsRequired(true);
$mForm->SetHelper("<p>Format <b>Kode Program Studi</b> pada umumnya berupa 5 digit angka (disesuaikan dengan ketentuan yang berlaku di PTS yang bersangkutan). Dengan ketentuan 3 digit awal mewakili kode jurusan. </p><p><b>contoh:</b><br><b>19</b>025</p>");

$mForm->CreateInputForm();
$mForm->SetIsRequired(true);
$mForm->SetType('text');
$mForm->SetName('fNama');
$mForm->SetCaption('Nama Lengkap');
$mForm->SetHelper("<b>example:</b><br>Teknologi Informasi");

$mForm->CreateInputForm();
$mForm->SetType('select');
$mForm->SetName('fJabatan');
$mForm->SetCaption('Jabatan');
$mForm->SetOptionValueFromDataTable($tResJabatanOption);

$mForm->CreateInputForm();
$mForm->SetIsRequired(true);
$mForm->SetType('select');
$mForm->SetName('fKotaLahir');
$mForm->SetCaption('Kota Lahir');
$mForm->SetOptionValueFromDataTable($tResKotaLahirOption);

$mForm->CreateInputForm();
$mForm->SetIsRequired(true);
$mForm->SetType('text');
$mForm->SetName('fTanggalLahir');
$mForm->SetCaption('Tanggal Lahir');
$mForm->SetClass("DatePicker");
$mForm->SetIsRequired(true);
$mForm->SetHelper("<p><b>format:</b><br>dd/mm/yyy</p><p><b>example:</b><br>23 Desember 2008 = 23/12/2008</p>");

$mForm->CreateInputForm();
$mForm->SetIsRequired(true);
$mForm->SetType('select');
$mForm->SetName('fKelamin');
$mForm->SetCaption('Jenis Kelamin');
$mForm->SetOptionValueFromDataTable($tResKelaminOption);

$mForm->CreateInputForm();
$mForm->SetIsRequired(true);
$mForm->SetType('select');
$mForm->SetName('fAgama');
$mForm->SetCaption('Agama');
$mForm->SetOptionValueFromDataTable($tResAgamaOption);

$mForm->CreateInputForm();
$mForm->SetIsRequired(true);
$mForm->SetType('select');
$mForm->SetName('fGoldarah');
$mForm->SetCaption('Golongan Darah');
$mForm->SetOptionValueFromDataTable($tResGoldarahOption);


$mForm->CreateInputForm();
$mForm->SetIsRequired(true);
$mForm->SetType('textarea');
$mForm->SetName('fAlamat');
$mForm->SetCaption('Alamat');
$mForm->SetHelper("<b>example:</b><br>Jl. Ir. H. Juanda No 347<br>Dago 40191");

$mForm->CreateInputForm();
$mForm->SetIsRequired(true);
$mForm->SetType('select');
$mForm->SetName('fKota');
$mForm->SetCaption('Kota');
$mForm->SetOptionValueFromDataTable($tResKotaOption);

$mForm->CreateInputForm();
$mForm->SetIsRequired(true);
$mForm->SetType('text');
$mForm->SetName('fTelepon');
$mForm->SetCaption('Nomor Telepon');
$mForm->SetHelper("<b>example:</b><br>Teknologi Informasi");




//SET FIELD SUPPORT
//HIDDEN FORM: ID Referer
/* EMPTY */
$mForm->SetFieldSupport("fKategori", 1201);
////


$mForm->PrintForm();
?>
